package com.hxkj.controller.timer;

import com.github.pagehelper.PageInfo;
import com.hxkj.common.annotation.SysLog;
import com.hxkj.domain.po.Article;
import com.hxkj.domain.po.ScheduleJobEntity;
import com.hxkj.domain.vo.ScheduleJobVO;
import com.hxkj.service.timer.ScheduleJobService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import com.platform.common.domain.to.PageTo;
import org.redisson.Redisson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

@RestController
@RequestMapping("/schedule")
public class ScheduleJobController {

    @Autowired
    private ScheduleJobService scheduleJobService;

    @RequestMapping(value = "/list")
    public Callable<ResultPageStruct<ScheduleJobVO>> jobList(@ModelAttribute ScheduleJobEntity jobEntity, @ModelAttribute PageTo pageParam){
        return () -> scheduleJobService.list(jobEntity == null?new ScheduleJobEntity():jobEntity, pageParam);
    }

    /**
     * 定时任务信息
     */
    @RequestMapping("/info")
    public Callable<ScheduleJobEntity> info(Long jobId){
        return () -> scheduleJobService.info(jobId);
    }

    /**
     * 保存定时任务
     */
    @SysLog("保存定时任务")
    @RequestMapping("/save")
    public void save(@ModelAttribute ScheduleJobVO scheduleJob) throws Exception{
        scheduleJobService.save(scheduleJob);
    }

    /**
     * 修改定时任务
     */
    @SysLog("修改定时任务")
    @RequestMapping("/update")
    public void update(@ModelAttribute ScheduleJobVO scheduleJob) throws Exception{
        scheduleJobService.update(scheduleJob);
    }

    /**
     * 删除定时任务
     */
    @SysLog("删除定时任务")
    @RequestMapping("/remove")
    public void delete(String jobIds) throws Exception{
        scheduleJobService.delete(jobIds);
    }

    /**
     * 立即执行任务
     */
    @SysLog("立即执行任务")
    @RequestMapping("/run")
    public void run(String jobIds) throws Exception{
        scheduleJobService.run(jobIds);
    }

    /**
     * 暂停定时任务
     */
    @SysLog("暂停定时任务")
    @RequestMapping("/pause")
    public void pause(String jobIds) throws Exception{
        scheduleJobService.pause(jobIds);
    }

    /**
     * 恢复定时任务
     */
    @SysLog("恢复定时任务")
    @RequestMapping("/resume")
    public void resume(String jobIds) throws Exception{
        scheduleJobService.resume(jobIds);
    }
}
